<template>
  <div class="pur-view">
    <!--视图-->
    <el-row>
      <el-col :span="20" :offset="2" class="c-b">
        <el-row class="m-b-10">
          <el-col :offset="2" :span="4">
            <div style="line-height: 56px;font-size: 18px;width:200px">审批过程：</div>
          </el-col>
          <!--同意显示同意-->
          <el-col v-if="this.purchase.purchaseAppStatus !== 3" :span="18" v-cloak>
            <el-steps :active="active" finish-status="success" space="20%" v-cloak>
              <el-step title="待申请"></el-step>
              <el-step title="待审批"></el-step>
              <el-step title="同意"></el-step>
              <el-step title="执行"></el-step>
            </el-steps>
          </el-col>
          <!--否决显示否决-->
          <el-col v-if="this.purchase.purchaseAppStatus === 3" :span="18" v-cloak>
            <el-steps :active="active" finish-status="success" space="20%" v-cloak>
              <el-step title="待申请"></el-step>
              <el-step title="待审批"></el-step>
              <el-step title="否决"></el-step>
              <el-step title="执行"></el-step>
            </el-steps>
          </el-col>
        </el-row>
        <el-row class="m-b-20">
          <el-row v-if="this.purchase.purchaseAppStatus === 0" v-cloak>
            <el-col  :offset="8" :span="4">
              <div class="opera" @click="findAllEmp(currPage,pageSize)">
                <div style="line-height: 30px;"><i class="el-icon-position"/></div>
                <span class="font-14">申请审批</span>
              </div>
            </el-col>
            <el-col  :span="4" >
              <div class="opera-no">
                <div style="line-height: 30px;"><i class="el-icon-d-arrow-left"/></div>
                <span class="font-14">撤销审批</span>
              </div>
            </el-col>
          </el-row>
          <el-row v-if="this.purchase.purchaseAppStatus === 1" v-cloak>
            <el-col  :offset="8" :span="4" >
              <div class="opera-no">
                <div style="line-height: 30px;"><i class="el-icon-position"/></div>
                <span class="font-14">申请审批</span>
              </div>
            </el-col>
            <el-col  :span="4" >
              <div class="opera" @click="repealApp">
                <div style="line-height: 30px;"><i class="el-icon-d-arrow-left"/></div>
                <span class="font-14">撤销审批</span>
              </div>
            </el-col>
          </el-row>
          <el-row v-if="this.purchase.purchaseAppStatus === 3" v-cloak>
            <el-col  :offset="8" :span="4" >
              <div class="opera" @click="findAllEmp(currPage,pageSize)">
                <div style="line-height: 30px;"><i class="el-icon-position"/></div>
                <span class="font-14">申请审批</span>
              </div>
            </el-col>
            <el-col  :span="4" >
              <div class="opera-no">
                <div style="line-height: 30px;"><i class="el-icon-d-arrow-left"/></div>
                <span class="font-14">撤销审批</span>
              </div>
            </el-col>
          </el-row>
          <!-- 员工表格dialog-->
          <el-dialog width="30%" title="申请审批" :visible.sync="innerDialog">
            <div style="margin-bottom: 20px"><span class="font-14-bold">说明：</span>以下人员拥有审批权限</div>
            <el-table :data="empList" style="width: 100%">
              <el-table-column prop="job.jobName" label="员工职位" >
              </el-table-column>
              <el-table-column prop="empName" label="员工姓名" >
              </el-table-column>
            </el-table>
            <el-row style="margin-top:10px">
              <el-col :span="16">
                <el-pagination layout="prev, pager, next, jumper" :total="totalSize" @current-change="changePage"
                               :current-page.sync="currPage" :page-size="pageSize"></el-pagination>
              </el-col>
            </el-row>
            <div style="margin-top: 20px;text-align: center">
              <el-button @click="saveApproval">申请审批</el-button>
            </div>
            <!--<el-checkbox-group v-model="checkedCities" @change="handleCheckedCitiesChange">
              <el-checkbox v-for="emp in empList" :label="emp.empName" :key="emp.empName">{{emp.empName}}</el-checkbox>
            </el-checkbox-group>-->
          </el-dialog>
        </el-row>
        <!--采购-->
        <el-row  class="b-g-f p-l-20 p-r-20 border-style">
          <el-row>
            <el-col :span="19" class="dialog__header">
              <span class="dialog__title">采购单</span>
            </el-col>
            <el-col :span="4" class="dialog__header" v-if="this.purchase.contractByContractId !== null">
              <el-button @click="goContract(purchase.contractByContractId.contractId)">查看关联订单</el-button>
            </el-col>
          </el-row>
          <el-form :model="purchase" ref="pur" label-width="100px" :rules="rules">
            <el-divider><span class="font-14-bold"></span></el-divider>
            <el-row>
              <el-col>
                <el-form-item label="主题:" prop="purchaseTheme">
                  <el-input v-model="purchase.purchaseTheme" style="width: 91%"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col>
                <el-form-item label="客户:" prop="customerByCustomerId.customerName">
                  <el-input :disabled="true" v-model="purchase.customerByCustomerId.customerName" style="width: 91%"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="供应联系人:">
                  <el-select v-model="purchase.purchaseContactName"  placeholder="未选" style="width: 79%">
                    <el-option v-for="(item,index) in contactList" :key="index" :label="item.contactName" :value="item.contactName">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="采购单号:">
                  <el-input :disabled="true" v-model="purchase.purchaseNo" style="width: 79%"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="采购日期:">
                  <el-date-picker v-model="purchase.purchaseDate" type="date" placeholder="选择日期" style="width: 79%"></el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="仓库:" prop="warehouseByWarehouseId">
                  <el-select v-model="purchase.warehouseByWarehouseId" value-key="warehouseId" placeholder="未选" style="width: 79%">
                    <el-option v-for="item in warehouseList" :key="item.warehouseId" :label="item.warehouseName" :value="item">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="预计到货日期:">
                  <el-date-picker v-model="purchase.purchasePredictDate" type="date" placeholder="选择日期" style="width: 79%"></el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="分类:">
                  <el-select v-model="purchase.purchaseSort"  placeholder="未选" style="width: 79%">
                    <el-option v-for="item in lxOptions" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="经手人:" prop="employeeByEmpId.empName">
                  <el-input :disabled="true" v-model="purchase.employeeByEmpId.empName" style="width: 79%">
                    <el-button @click="openEmpDialog" slot="append" icon="el-icon-search"></el-button>
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="状态:" >
                  <el-select :disabled="true" v-model="purchase.purchaseStatus"  placeholder="不可编辑" style="width: 79%">
                    <el-option v-for="item in ztsOptions" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="金额:" prop="purchaseAmount">
                  <el-input v-model.number="purchase.purchaseAmount" style="width: 79%">
                  </el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="付款票据:">
                  <el-input :disabled="true" v-model.number="purchase.purchaseBill" style="width: 79%"/>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item  label="已付金额:">
                  <el-input :disabled="true" v-model.number="purchase.purchasePaid" style="width: 79%"/>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="关联订单客户:">
                  <el-input v-if="this.purchase.customerByConCustomerId  !== null" :disabled="true" v-model="purchase.customerByConCustomerId.customerName" style="width: 79%"></el-input>
                </el-form-item>
                <div class="form-inline" v-show="isCustomer">
                  <el-input  v-model="customerValue" clearable size="medium" placeholder="拼音.字母.关键字" style="width: 37%"></el-input>
                  <el-button @click="findCustomer" size="medium" icon="el-icon-search"></el-button>
                  <el-popover placement="top" v-model="visible">
                    <div style="margin-bottom: 10px">
                      <span>查询条件:{{customerValue}}</span>
                      <span @click="closeEmp" class="cursor" style="float: right"><i class="el-icon-error"></i></span>
                    </div>
                    <ul class="cu-ul" v-if="customerList2 !== ''">
                      <li @click="choiceCustomer2(item)" v-for="item in customerList2">{{item.customerName}}</li>
                    </ul>
                    <div style="margin: 5px 0;text-align: center" v-if="customerList2 == ''">
                      <i class="el-icon-warning-outline"/>没有符合条件的客户！
                    </div>
                  </el-popover>
                  <el-tooltip class="item" effect="dark" content="浏览选择客户" placement="bottom">
                    <el-button @click="innerVisible(cusCurrPage,cusPageSize)" size="medium" icon="el-icon-s-operation"></el-button>
                  </el-tooltip>
                </div>
              </el-col>
              <el-col :span="12">
                <el-form-item label="关联订单:">
                  <el-select v-model="purchase.contractByContractId" value-key="contractId" clearable placeholder="未选" style="width: 79%">
                    <el-option v-for="item in contractList" :key="item.contractId" :label="item.contractTheme" :value="item">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col>
                <el-form-item label="备注:">
                  <el-input v-model="purchase.purchaseNote" style="width: 91%" type="textarea" :autosize="{ minRows: 2, maxRows: 4}" ></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col>
                <el-form-item label="采购物品明细:" style="width: 92%">
                  <el-row>
                    <el-col :span="4" :offset="16">
                      <span class="cursor" @click="openPro()"><i class="el-icon-edit"></i>编辑明细</span>
                    </el-col>
                    <el-col :span="4">
                      <span class="cursor" @click="printPdf(purchase.purchaseId)"><i class="el-icon-printer"></i>打印单据</span>
                    </el-col>
                  </el-row>
                </el-form-item>
                <div class="detail">
                  <el-table :data="detailList" style="width: 100%" border show-summary>
                    <el-table-column prop="productByProductId.productName" label="产品名" >
                    </el-table-column>
                    <el-table-column prop="productByProductId.productModel" label="型号" >
                    </el-table-column>
                    <el-table-column prop="productDetailCount" label="数量" >
                    </el-table-column>
                    <el-table-column prop="productDetailIntoNum" label="已入库" >
                    </el-table-column>
                    <el-table-column prop="productDetailOutNum" label="未入库" >
                    </el-table-column>
                    <el-table-column prop="productDetailPrice" label="单价" >
                      <template slot-scope="scope">
                        ￥{{scope.row.productDetailPrice}}
                      </template>
                    </el-table-column>
                    <el-table-column prop="productDetailMoney" label="金额" >
                      <template slot-scope="scope">
                        ￥{{ (scope.row.productDetailMoney = scope.row.productDetailPrice *scope.row.productDetailCount)}}
                      </template>
                    </el-table-column>
                    <el-table-column prop="productDetailRemarks" label="备注" >
                    </el-table-column>
                  </el-table>
                </div>
              </el-col>
            </el-row>
            <el-row>
              <el-col>
                <el-form-item label="入库情况:" style="width: 92%"></el-form-item>
                <div class="detail">
                  <el-table :data="storageList" style="width: 100%" border>
                    <el-table-column prop="storageTheme" label="主题" width="150">
                      <template slot-scope="scope">
                        <span>{{scope.row.storageTheme}}</span>
                        <el-tooltip class="item" effect="dark" content="打开详细页面" placement="bottom">
                          <router-link :to="{path:'/storageview',query: {stoId: scope.row.storageId}}">
                            <span style="color: #333333"><i class="el-icon-caret-right"></i></span>
                          </router-link>
                        </el-tooltip>
                      </template>
                    </el-table-column>
                    <el-table-column prop="storageDate" label="填单时间" >
                      <template slot-scope="scope">
                        <span>{{scope.row.storageDate | formatDateJudge}}</span>
                      </template>
                    </el-table-column>
                    <el-table-column prop="storageExecutorDate" label="执行日期" >
                      <template slot-scope="scope">
                        <span>{{scope.row.storageExecutorDate | formatDateJudge}}</span>
                      </template>
                    </el-table-column>
                    <el-table-column label="入库明细" width="500">
                      <template slot-scope="scope">
                        <el-table :data="scope.row.storageDetailsByStorageId" style="width: 100%" border show-summary>
                          <el-table-column type="index" label="序号" width="50">
                          </el-table-column>
                          <el-table-column prop="productByProductId.productName" label="产品名" >
                          </el-table-column>
                          <el-table-column prop="productByProductId.productModel" label="型号" >
                          </el-table-column>
                          <el-table-column prop="storageDetailNum" label="入库量" >
                          </el-table-column>
                          <el-table-column prop="storageDetailNote" label="备注" >
                          </el-table-column>
                        </el-table>
                      </template>
                    </el-table-column>
                    <el-table-column prop="employeeByStoEmployeeId.empName" label="填单人" ></el-table-column>
                    <el-table-column label="状态" >
                      <template slot-scope="scope">
                        <span v-if="scope.row.storageStatus === 1">未入库</span>
                        <span v-if="scope.row.storageStatus === 2">已入库</span>
                      </template>
                    </el-table-column>
                  </el-table>
                </div>
              </el-col>
            </el-row>
            <el-row>
              <el-col>
                <el-form-item label="审批状态:" style="width:91%">
                  <div v-if="this.purchase.purchaseId !== 0">
                    <div v-if="this.purchase.purchaseAppStatus === 0">
                      <span>待申请</span>
                      <el-tooltip class="item" effect="dark" content="待申请" placement="bottom">
                        <i class="el-icon-more font-18"></i>
                      </el-tooltip>
                    </div>
                    <div v-if="this.purchase.purchaseAppStatus === 1">
                      <span>待审批</span>
                      <el-tooltip class="item" effect="dark" content="待审批" placement="bottom">
                        <i class="el-icon-s-opportunity font-18"></i>
                      </el-tooltip>
                    </div>
                    <div v-if="this.purchase.purchaseAppStatus === 2">
                      <span>同意</span>
                      <el-tooltip class="item" effect="dark" content="同意" placement="bottom">
                        <i class="el-icon-circle-check font-18"></i>
                      </el-tooltip>
                      <span>审批人：{{purchase.employeeByAppEmpId.empName}}</span>
                    </div>
                    <div v-if="this.purchase.purchaseAppStatus === 3">
                      <span>否决</span>
                      <el-tooltip class="item" effect="dark" content="否决" placement="bottom">
                        <i class="el-icon-circle-close font-18"></i>
                      </el-tooltip>
                      <span>审批人：{{purchase.employeeByAppEmpId.empName}}</span>
                    </div>
                  </div>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col>
                <el-form-item label="审批记录:" style="width:91%">
                  <el-row></el-row>
                  <el-row :key="index" v-for="(app,index) in approvalRecordList">
                    <div class="border-bo" >
                      <div class="font-13-bold">
                        <span>申请：</span>
                        <span class="margin-r-3">{{app.employeeByApplicantEmpId.empName}}<i class="el-icon-right"/> boss用户</span>
                        <span>{{app.approvalRecordDate | formatDateJudge}}</span>
                      </div>
                      <div class="font-13" v-if="app.employeeByApprovalEmpId !== null">
                        <span class="margin-r-3"><i class="el-icon-minus"/>{{app.employeeByApprovalEmpId.empName}}</span>
                        <span class="margin-r-3">{{app.approvalRecordTime | formatDate}}</span>
                        <span class="margin-r-3">{{app.approvalRecordOper}}</span>
                        <span>备注：{{app.approvalRecordNote}}</span>
                      </div>
                    </div>
                  </el-row>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12" :offset="7">
                <el-form-item>
                  <span v-if="this.purchase.purchaseAppStatus !== 2">
                    <el-button @click="addPurchase" type="primary">保存</el-button>
                    <el-button @click="repealPur" type="danger">删除</el-button>
                  </span>
                  <span v-if="this.purchase.purchaseStatus !== 4 && this.purchase.purchaseAppStatus === 2">
                    <span v-if="this.storageList.length === 0"><el-button @click="repealSto" type="primary" plain><i class="el-icon-bottom"/>生成入库单</el-button></span>
                    <span v-if="this.storageList.length !== 0"><el-button @click="repealStoAga" type="primary" plain><i class="el-icon-bottom"/>再次生成入库单</el-button></span>
                  </span>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
          <!--内层dialog-->
          <el-dialog width="30%" title="全部客户" :visible.sync="innerDialogCus" append-to-body>
            <!--选择客户-->
            <el-table :data="customerList" style="width: 100%">
              <el-table-column prop="customerId" label="客户编号" >
              </el-table-column>
              <el-table-column prop="customerName" label="客户名" >
              </el-table-column>
              <el-table-column label="请选择" >
                <template slot-scope="scope">
                  <el-button size="mini" @click="choiceCustomer(scope.row)" icon="el-icon-check" type="primary" circle style="margin-left: 10px"></el-button>
                </template>
              </el-table-column>
            </el-table>
            <el-row style="margin-top:10px">
              <el-col :span="16">
                <el-pagination layout="prev, pager, next, jumper" :total="cusTotalSize" @current-change="cusChangePage"
                               :current-page.sync="cusCurrPage" :page-size="cusPageSize"></el-pagination>
              </el-col>
            </el-row>
          </el-dialog>
          <el-dialog width="30%" title="人员选择" :visible.sync="innerDialogEmp" append-to-body @close="closeInnerDialogEmp">
            <div>
              <el-collapse v-model="activeName">
                <el-collapse-item v-for ="(dept,index) in deptList" :title="dept.deptName" :key="index" :name="dept.deptId">
                  <ul class="emp-ul">
                    <li @click="choiceEmp(emp)" v-for="(emp,index) in dept.employeeByDeptId">
                      <span v-if="index !== dept.employeeByDeptId.length-1" class="line-style"></span>
                      <span v-if="index === dept.employeeByDeptId.length-1" class="line-style-end"></span>
                      <span class="">{{emp.empName}}</span>
                    </li>
                  </ul>
                </el-collapse-item>
              </el-collapse>
            </div>
          </el-dialog>
        </el-row>
        <!--付款计划/付款记录/付款票据-->
        <el-row type="flex" class="m-t-30">
          <el-col :span="11" class="m-b-20 ">
            <!--付款计划-->
            <el-row class="m-b-20 b-g-f border-style" >
              <div class="p-10-20 f-w">
                <el-icon class="el-icon-chat-line-square"></el-icon>
                <span>付款计划(应付)</span>
                <el-tooltip class="item" effect="dark" content="新建" placement="bottom">
                <span @click="newPayPlan">
                  <el-icon class="el-icon-plus cursor" ></el-icon>
                </span>
                </el-tooltip>
              </div>
              <div class="p-10-20">
                <el-row :key="index" v-for="(pay,index) in paymentPlanList" style="padding-bottom: 5px">
                  <el-icon class="el-icon-star-on"/>
                  <span @click="openPayView(pay.paymentPlanId)" class="cursor margin-r-5">￥{{pay.paymentPlanAmount}}</span>
                  <span v-if="pay.paymentPlanAppStatus === 2" class="margin-r-5 c-r">（审核通过）</span>
                  <span v-if="pay.paymentPlanPeriods !== null" class="margin-r-5">第{{payPlanQcOptions[pay.paymentPlanPeriods-1].label}}期</span>
                  <span class="margin-r-5">{{pay.paymentPlanDate | formatDateJudge}}</span>
                  <span v-if="pay.paymentPlanStatus !== null" class="margin-r-5">{{payPlanStaOptions[pay.paymentPlanStatus-1].label}}</span>
                  <span v-if="pay.paymentPlanStatus !== 2" @click="clickCreatePayRecords(pay)" class="margin-r-5 cursor c-dl"><el-icon class="el-icon-right"/> 付款</span>
                </el-row>
              </div>
            </el-row>
            <!--付款票据-->
            <el-row class="b-g-f border-style">
              <div class="p-10-20 f-w">
                <el-icon class="el-icon-chat-line-square"></el-icon>
                <span>付款票据</span>
                <el-tooltip class="item" effect="dark" content="新建" placement="bottom">
                <span @click="newPaymentInvoice">
                  <el-icon class="el-icon-plus cursor" ></el-icon>
                </span>
                </el-tooltip>
              </div>
              <div class="p-10-20">
                <el-row :key="index" v-for="(pay,index) in paymentInvoiceList" style="padding-bottom: 5px">
                  <el-icon class="el-icon-star-on"/>
                  <span class="margin-r-5">{{pay.paymentInvoiceAbstract}}</span>
                  <span @click="openPayInvoice(pay)" class="cursor margin-r-5">￥{{pay.paymentInvoiceAmount}}</span>
                  <span v-if="pay.paymentInvoicePeriods !== null" class="margin-r-5">第{{payInvoiceQcOptions[pay.paymentInvoicePeriods-1].label}}期</span>
                  <span class="margin-r-5">{{pay.paymentInvoiceTicketDate | formatDateJudge}}</span>
                  <span v-if="pay.paymentInvoiceWhetherPayPlan === 1" @click="clickCreatePayPlan(pay)" class="margin-r-5 cursor c-dl"><el-icon class="el-icon-right"/> 付款计划</span>

                </el-row>
              </div>
            </el-row>
          </el-col>
          <!--付款记录-->
          <el-col :offset="1" :span="12" class="m-b-20 b-g-f border-style">
            <div class="p-10-20 f-w ">
              <el-icon class="el-icon-document"></el-icon>
              <span>付款记录</span>
              <el-tooltip class="item" effect="dark" content="新建" placement="bottom">
                <span @click="newPaymentRecords">
                  <el-icon class="el-icon-plus cursor" ></el-icon>
                </span>
              </el-tooltip>
            </div>
            <div class="p-10-20">
              <el-row :key="index" v-for="(pay,index) in paymentRecordsList" style="padding-bottom: 5px">
                <el-icon class="el-icon-star-on"/>
                <span @click="openPayRecords(pay)" class="cursor margin-r-5">￥{{pay.paymentRecordsAmount}}</span>
                <span v-if="pay.paymentRecordsPeriods !== null" class="margin-r-5">第{{payRecordsQcOptions[pay.paymentRecordsPeriods-1].label}}期</span>
                <span class="margin-r-5">{{pay.paymentRecordsDate | formatDateJudge}}</span>
                <span v-if="pay.paymentRecordsWhetherTicket === 1" @click="clickCreatePayInvoice(pay)" class="margin-r-5 cursor c-dl"><el-icon class="el-icon-right"/> 收票</span>
              </el-row>
            </div>
          </el-col>
        </el-row>
        <!--付款计划dialog-->
        <el-dialog title="付款计划" :visible.sync="dialogPla" width="60%" style="color: #333333"
               @close="closeDialogPayPlan">
          <el-form :model="paymentPlan" ref="payPlan" label-width="100px" :rules="payPlanRules">
            <hr style="margin-bottom: 15px">
            <el-row>
              <el-col>
                <el-form-item label="(供应商)客户:">
                  <el-input :disabled="true" v-model="paymentPlan.customerByCustomerId.customerName" style="width: 91%"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="计划付款日期:">
                  <el-date-picker v-model="paymentPlan.paymentPlanDate" type="date" placeholder="选择日期" style="width: 79%"></el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="期次:" prop="paymentPlanPeriods">
                  <el-select v-model="paymentPlan.paymentPlanPeriods" placeholder="未选"  style="width: 79%">
                    <el-option :disabled="item.disabled" v-for="item in payPlanQcOptions" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="金额:" prop="paymentPlanAmount">
                  <el-input v-model.number="paymentPlan.paymentPlanAmount" style="width: 79%"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="负责人:">
                  <el-input v-model="paymentPlan.employeeByEmpId.empName" style="width: 79%">
                    <el-button slot="append" icon="el-icon-search" ></el-button>
                  </el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="采购单:">
                  <el-input :disabled="true" v-model="paymentPlan.purchaseByPurchaseId.purchaseTheme" style="width: 79%"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="状态:" >
                  <el-select v-model="paymentPlan.paymentPlanStatus" placeholder="未选" style="width: 79%">
                    <el-option v-for="item in payPlanStaOptions" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col>
                <el-form-item label="备注:">
                  <el-input v-model="paymentPlan.paymentPlanNote" type="textarea" :autosize="{ minRows: 2, maxRows: 4}" placeholder="请输入内容" style="width: 91%"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col>
                <el-form-item label="审批状态:" style="width:91%">
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col>
                <el-form-item label="审批记录:" style="width:91%">
                  <el-row></el-row>
              </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12" :offset="6">
                <el-form-item>
                  <el-button @click="addPayPlanJudge" type="primary">保存</el-button>
                  <el-button @click="dialogPla = false">取消</el-button>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </el-dialog>
        <!--付款记录dialog-->
        <el-dialog title="付款记录" :visible.sync="dialogPay" width="60%" style="color: #333333"
                    @close="closeDialogPayRecords">
          <el-form :model="paymentRecords" ref="payRecords" label-width="100px" :rules="payRecordsRules">
            <hr style="margin-bottom: 15px">
            <el-row>
              <el-col>
                <el-form-item label="采购单:">
                  <el-input :disabled="true" v-model="paymentRecords.purchaseByPurchaseId.purchaseTheme" style="width: 91%"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="期次:">
                  <el-select :disabled="true" v-model="paymentRecords.paymentRecordsPeriods" placeholder="未选"  style="width: 79%">
                    <el-option v-for="item in payRecordsQcOptions" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="付款日期:" prop="paymentRecordsDate">
                  <el-date-picker v-model="paymentRecords.paymentRecordsDate" type="date" placeholder="选择日期" style="width: 79%"></el-date-picker>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="金额:">
                  <el-input :disabled="true" v-model="paymentRecords.paymentRecordsAmount" style="width: 79%"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="付款方式:" prop="paymentRecordsPayStyle">
                  <el-select v-model="paymentRecords.paymentRecordsPayStyle" placeholder="未选"  style="width: 79%">
                    <el-option v-for="item in payRecordsFsOptions" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="是否收票:">
                  <el-radio-group v-model="paymentRecords.paymentRecordsWhetherTicket">
                    <el-radio :label="1">未收</el-radio>
                    <el-radio :label="2">已收</el-radio>
                    <el-radio :label="3">无需发票</el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="客户:">
                  <el-input :disabled="true" v-model="paymentRecords.customerByCustomerId.customerName" style="width: 79%"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="对应对货单:" >
                  <el-input :disabled="true" style="width: 79%"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="经手人:">
                  <el-input :disabled="true" v-model="paymentRecords.employeeByEmpId.empName" style="width: 79%"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="分类:" >
                  <el-select v-model="paymentRecords.paymentRecordsClassify" placeholder="未选"  style="width: 79%">
                    <el-option v-for="item in payRecordsClaOptions" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col>
                <el-form-item label="备注:">
                  <el-input v-model="paymentRecords.paymentRecordsNote" type="textarea" :autosize="{ minRows: 2, maxRows: 4}" placeholder="请输入内容" style="width: 91%"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12" :offset="6">
                <el-form-item>
                  <el-button @click="addPayRecords" type="primary">保存</el-button>
                  <el-button @click="dialogPay = false">取消</el-button>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </el-dialog>
        <!--采购发票dialog-->
        <el-dialog title="采购发票" :visible.sync="dialogTin" width="60%" style="color: #333333"
                   @close="closeDialogPayInvoice" >
          <el-form :model="paymentInvoice" ref="payInvoice" label-width="100px" :rules="payInvoiceRules">
            <hr style="margin-bottom: 15px">
            <el-row>
              <el-col :span="12">
                <el-form-item label="摘要:" prop="paymentInvoiceAbstract">
                  <el-input v-model="paymentInvoice.paymentInvoiceAbstract "style="width:79%"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="票据类型:" prop="paymentInvoicePaperType">
                  <el-select v-model="paymentInvoice.paymentInvoicePaperType" placeholder="未选"  style="width: 79%">
                    <el-option v-for="item in payInvoiceFlOptions" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="金额:" prop="paymentInvoiceAmount">
                  <el-input v-model.number="paymentInvoice.paymentInvoiceAmount" style="width: 79%"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="收票日期:" prop="paymentInvoiceTicketDate">
                  <el-date-picker v-model="paymentInvoice.paymentInvoiceTicketDate" type="date" placeholder="选择日期" style="width: 79%"></el-date-picker>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col>
                <el-form-item label="采购单:">
                  <el-input :disabled="true" v-model="paymentInvoice.purchaseByPurchaseId.purchaseTheme"  style="width: 91%">
                  </el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="经手人:" prop="employeeByEmpId.empName">
                  <el-input v-model="paymentInvoice.employeeByEmpId.empName" style="width: 79%">
                    <el-button @click="openEmpDialog" slot="append" icon="el-icon-search"></el-button>
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="期次:">
                  <el-select v-model="paymentInvoice.paymentInvoicePeriods" placeholder="未选"  style="width: 79%">
                    <el-option :disabled="item.disabled" v-for="item in payInvoiceQcOptions" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col>
                <el-form-item label="供应商/客户:">
                  <el-input :disabled="true" v-model="paymentInvoice.customerByCustomerId.customerName" style="width: 91%"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="是否付款:">
                  <el-select :disabled="true" placeholder="未选" v-model="paymentInvoice.paymentInvoiceWhetherPay" style="width: 79%" >
                    <el-option v-for="item in payInvoicePayOptions" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="是否付款计划:" >
                  <el-select :disabled="true" placeholder="未选"  style="width: 79%" v-model="paymentInvoice.paymentInvoiceWhetherPayPlan">
                    <el-option v-for="item in payInvoicePayPlanOptions" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col>
                <el-form-item label="发票号码:">
                  <el-input :disabled="true" v-model="paymentInvoice.paymentInvoiceNo" placeholder="自动生成" style="width: 91%"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col>
                <el-form-item label="备注:">
                  <el-input v-model="paymentInvoice.paymentInvoiceNote" type="textarea" :autosize="{ minRows: 2, maxRows: 4}" placeholder="请输入内容"  style="width: 91%"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12" :offset="6">
                <el-form-item>
                  <el-button @click="addPayInvoiceJudge" type="primary">保存</el-button>
                  <el-button @click="dialogTin = false">取消</el-button>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
          <!--内层dialog员工-->
          <el-dialog width="30%" title="人员选择" :visible.sync="innerDialogEmp" append-to-body
                     @close="closeInnerDialogEmp">
            <div>
              <el-collapse v-model="activeName">
                <el-collapse-item v-for ="(dept,index) in deptList" :title="dept.deptName" :key="index" :name="dept.deptId">
                  <ul class="emp-ul">
                    <li @click="choiceEmp(emp)" v-for="(emp,index) in dept.employeeByDeptId">
                      <span v-if="index !== dept.employeeByDeptId.length-1" class="line-style"></span>
                      <span v-if="index === dept.employeeByDeptId.length-1" class="line-style-end"></span>
                      <span class="">{{emp.empName}}</span>
                    </li>
                  </ul>
                </el-collapse-item>
              </el-collapse>
            </div>
          </el-dialog>
        </el-dialog>
      </el-col>
      <!--抽屉弹框-->
      <el-drawer title="编辑采购明细" size="60%":visible.sync="drawer"
                 :direction="'rtl'" @close="closeDrawer"  style="font-size:20px">
        <div class="m-l-20 font-18">
          <div class="m-b-10"><span>产品列表</span></div>
          <el-tree :data="proList" @node-click="clickPro" class="m-b-20"
                   node-key="productClassifyId" ref="tree" highlight-current :props="defaultProps">
          </el-tree>
        </div>
        <div class="m-l-20 w-95 font-16">
          <div class="m-b-10"><span>明细表格</span></div>
          <div class="detail">
            <el-table :data="editDetailList" style="width: 100%" border show-summary>
              <el-table-column prop="productByProductId.productName" label="产品名" >
              </el-table-column>
              <el-table-column prop="productByProductId.productModel" label="型号" >
              </el-table-column>
              <el-table-column label="数量" width="150">
                <template slot-scope="scope">
                  <el-input-number v-model="scope.row.productDetailCount" :min="1" :max="1000" size="mini"></el-input-number>
                  <span style="display: none">{{scope.row.productDetailOutNum = scope.row.productDetailCount}}</span>
                </template>
              </el-table-column>
              <el-table-column prop="productDetailPrice" label="单价" width="150">
                <template slot-scope="scope">
                  <el-input-number :min="1" v-model="scope.row.productDetailPrice" size="small"></el-input-number>
                </template>
              </el-table-column>
              <el-table-column prop="productDetailMoney" label="金额" >
                <template slot-scope="scope">
                  {{ (scope.row.productDetailMoney = scope.row.productDetailPrice *scope.row.productDetailCount)}}
                </template>
              </el-table-column>
              <el-table-column label="备注" width="150">
                <template slot-scope="scope">
                  <el-input v-model="scope.row.productDetailRemarks" size="small">
                  </el-input>
                </template>
              </el-table-column>
              <el-table-column prop="" label="操作" width="70">
                <template slot-scope="scope">
                  <el-tooltip class="item" effect="dark" content="删除" placement="bottom">
                    <el-button size="mini" @click="deleteDetail(scope.row)"
                               icon="el-icon-delete" type="danger" circle></el-button>
                  </el-tooltip>
                </template>
              </el-table-column>
            </el-table>
          </div>
        </div>
        <el-row>
          <el-col class="m-t-20 m-l-20">
            <el-button @click="savePurchaseDetail"  type="primary">确认</el-button>
            <el-button @click="drawer = false">取消</el-button>
          </el-col>
        </el-row>
      </el-drawer>
    </el-row>
  </div>
</template>

<script>
  import {formatTimeToStr} from '../assets/format.js'
  export default {
    data () {
      return {
        emp:{},
        contactList: [], // 客户联系人集合
        detailList: [],//明细集合
        warehouseList: [],// 仓库集合
        contractList: [],// 合同订单集合
        pageSize: 5, // 分页页大小
        currPage: 1, // 当前页码，默认为1
        totalSize: 0, // 总记录数
        empList:[],// 所有Boss用户
        innerDialog: false,// bossDialog
        active: 0, //审批步骤初始值
        // 撤销审批对象
        approval:{
          approvalId:0,
          approvalTheme:'',
          approvalStay:'',
          approvalStatus: '',
          approvalClassify:'',
          approvalOperation:'',
          approvalContent:'',
          approvalDate:'',
          approvalTime:'',
          purchaseByPurchaseId:'',
          employeeByApplicantEmpId:'',
          employeeByApprovalEmpId:null
        },
        approvalRecordList:[],// 审批记录集合
        // 审批记录
        approvalRecord:{
          approvalRecordId:0,
          approvalRecordTime:'',
          approvalRecordOper:'',
          approvalRecordNote:'',
          approvalRecordDate:'',
          purchaseByPurchaseId:'',
          employeeByApplicantEmpId:'',
          employeeByApprovalEmpId:null
        },
        // 采购
        purchase: {
          purchaseId: 0,
          purchaseTheme: '',
          purchaseNo: '',
          purchaseDate: '',
          purchasePredictDate: '',
          purchaseStatus: '',
          purchaseSort: '',
          purchaseAmount: '',
          purchaseNote: '',
          purchaseContactName: '',
          purchaseBill: '',
          purchasePaid: '',
          purchaseAppStatus: 0,
          purchaseReturn: 1,
          customerByCustomerId: '',
          employeeByEmpId: '',
          customerByConCustomerId:'',
          contractByContractId:'',
          employeeByAppEmpId:'',
          warehouseByWarehouseId:''
        },
        drawer: false, //抽屉
        proList:[],// 所有商品
        pro:{},
        editDetail:{
          productByProductId:'',
          purchaseByPurchaseId:{},
          productDetailCount: 1,
          productDetailOutNum:0,
          productDetailIntoNum:0,
          productDetailPrice:0,
          productDetailMoney: 0,
          productDetailRemarks: ''
        },
        editDetailList: [],//明细操作集合
        // 树形结构label，children
        defaultProps: {
          label: 'productClassifyName',
          children:'children'
        },
        rules: {
          purchaseTheme: [{
            required: true,
            message: '必须填',
            trigger: 'blur'
          }],
          'customerByCustomerId.customerName': [
            { required: true, message: '请选择客户', trigger: 'blur' }
          ],
          'employeeByEmpId.empName': [
            { required: true, message: '请选择负责人', trigger: 'blur' }
          ],
          purchaseAmount: [
            { required: true, message: '必须填'},
            { type: 'number', message: '必须为数字'}
          ],
          warehouseByWarehouseId: [
            { required: true, message: '必须填', trigger: 'blur' }
          ],
        },
        cusPageSize: 5, // 分页页大小
        cusCurrPage: 1, // 当前页码，默认为1
        cusTotalSize: 0, // 总记录数
        customerList:[],// 表格客户集合
        isCustomer: true, // 客户搜索显示
        innerDialogCus: false,// 内层dialog客户
        innerDialogEmp: false,// 内层dialog员工
        activeName: [],
        deptList:[],
        customerValue:'',// 模糊查询客户输入值
        customerList2:[],// 模糊客户集合
        visible: false,// 模糊搜索结果显示
        //入库单
        storage: {
          storageId: 0,
          storageTheme: '',
          storageDate: '',
          storageStatus: '',
          storageNote: '',
          storageExecutorDate: '',
          customerByCustomerId: '',
          employeeByStoEmployeeId: '',
          employeeByAffEmployeeId: '',
          purchaseByPurchaseId: '',
          returnByReturnId: '',
          warehouseByWarehouseId: ''
        },
        storageList:[],//入库单集合
        stoDetail:{
          storageDetailId:0,
          storageDetailNum:'',
          storageDetailNote:'',
          storageByStorageId:null,
          productByProductId:''
        },
        stoDetailList: [],//明细集合
        lxOptions: [{
          value: 1,
          label: '大宗采购'
        }, {
          value: 2,
          label: '零星采购'
        }],
        ztsOptions: [{
          value: 1,
          label: '1新采购'
        }, {
          value: 2,
          label: '2生成入库单'
        }, {
          value: 3,
          label: '3部分入库'
        }, {
          value: 4,
          label: '4入库完成'
        }],
        dialogPla:false,
        dialogPay:false,
        dialogTin:false,
        paymentPlanList:[],
        paymentPlan:{
          paymentPlanId:0,
          paymentPlanAmount:'',
          paymentPlanDate:'',
          paymentPlanPeriods:'',
          paymentPlanStatus:'',
          paymentPlanNote:'',
          paymentPlanAppStatus:0,
          customerByCustomerId:'',
          employeeByEmpId:'',
          purchaseByPurchaseId:'',
          employeeByAppEmpId:null
        },
        payPlanRules: {
          paymentPlanAmount: [
            { required: true, message: '必须填'},
            { type: 'number', message: '必须为数字'}
          ],
          paymentPlanPeriods: [
            { required: true, message: '必须填', trigger: 'blur' }
          ]
        },
        payPlanQcOptions: [{
          value: 1,
          label: '1',
          disabled:false
        }, {
          value: 2,
          label: '2',
          disabled:false
        }, {
          value: 3,
          label: '3',
          disabled:false
        }, {
          value: 4,
          label: '4',
          disabled:false
        }, {
          value: 5,
          label: '5',
          disabled:false
        }, {
          value: 6,
          label: '6',
          disabled:false
        },{
          value: 7,
          label: '7',
          disabled:false
        }, {
          value: 8,
          label: '8',
          disabled:false
        }, {
          value: 9,
          label: '9',
          disabled:false
        }, {
          value: 10,
          label: '10',
          disabled:false
        }, {
          value: 11,
          label: '11',
          disabled:false
        }, {
          value: 12,
          label: '12',
          disabled:false
        }],
        payPlanStaOptions: [{
          value: 1,
          label: '未付'
        }, {
          value: 2,
          label: '已付'
        }, {
          value: 3,
          label: '不提醒'
        }],
        paymentRecordsList:[],
        paymentRecords:{
          paymentRecordsId:0,
          paymentRecordsPeriods:'',
          paymentRecordsDate:'',
          paymentRecordsAmount:'',
          paymentRecordsPayStyle:'',
          paymentRecordsWhetherTicket:'',
          paymentRecordsClassify:'',
          paymentRecordsNote:'',
          employeeByEmpId:'',
          customerByCustomerId:'',
          purchaseByPurchaseId:'',
          paymentPlanByPaymentPlanId:'',
          returnByReturnId:null
        },
        payRecordsRules: {
          paymentRecordsDate: [
            { required: true, message: '必须填', trigger: 'blur' }
          ],
          paymentRecordsPayStyle: [
            { required: true, message: '必须填', trigger: 'blur' }
          ]
        },
        payRecordsRadio:1,
        payRecordsQcOptions: [{
          value: 1,
          label: '1',
          disabled:false
        }, {
          value: 2,
          label: '2',
          disabled:false
        }, {
          value: 3,
          label: '3',
          disabled:false
        }, {
          value: 4,
          label: '4',
          disabled:false
        }, {
          value: 5,
          label: '5',
          disabled:false
        }, {
          value: 6,
          label: '6',
          disabled:false
        },{
          value: 7,
          label: '7',
          disabled:false
        }, {
          value: 8,
          label: '8',
          disabled:false
        }, {
          value: 9,
          label: '9',
          disabled:false
        }, {
          value: 10,
          label: '10',
          disabled:false
        }, {
          value: 11,
          label: '11',
          disabled:false
        }, {
          value: 12,
          label: '12',
          disabled:false
        }],
        payRecordsFsOptions: [{
          value: 1,
          label: '支票'
        }, {
          value: 2,
          label: '现金'
        }, {
          value: 3,
          label: '邮政付款'
        },{
          value: 4,
          label: '电汇'
        }, {
          value: 5,
          label: '网上银行'
        },{
          value: 6,
          label: '其他'
        }],
        payRecordsClaOptions: [{
          value: 1,
          label: '购货款'
        }, {
          value: 2,
          label: '转账'
        }, {
          value: 3,
          label: '抵债付款'
        }],
        paymentInvoiceList: [],
        paymentInvoice:{
          paymentInvoiceId:0,
          paymentInvoiceAbstract:'',
          paymentInvoicePaperType:'',
          paymentInvoiceTicketDate:'',
          paymentInvoiceAmount:'',
          paymentInvoicePeriods:'',
          paymentInvoiceWhetherPay:'',
          paymentInvoiceWhetherPayPlan:'',
          paymentInvoiceNo:'',
          paymentInvoiceNote:'',
          customerByCustomerId:{},
          purchaseByPurchaseId:'',
          employeeByEmpId:{}
        },
        payInvoiceRules: {
          paymentInvoiceAbstract: [
            { required: true, message: '必须填', trigger: 'blur'},
          ],
          paymentInvoicePaperType: [
            { required: true, message: '必须填', trigger: 'blur'},
          ],
          paymentInvoiceAmount: [
            { required: true, message: '必须填'},
            { type: 'number', message: '必须为数字'}
          ],
          paymentInvoiceTicketDate: [
            { required: true, message: '必须填', trigger: 'blur' }
          ],
          'employeeByEmpId.empName': [
            { required: true, message: '请选择负责人', trigger: 'blur' }
          ],
        },
        payInvoiceQcOptions: [{
          value: 1,
          label: '1'
        }, {
          value: 2,
          label: '2'
        }, {
          value: 3,
          label: '3'
        }, {
          value: 4,
          label: '4'
        }, {
          value: 5,
          label: '5'
        }, {
          value: 6,
          label: '6'
        },{
          value: 7,
          label: '7'
        }, {
          value: 8,
          label: '8'
        }, {
          value: 9,
          label: '9'
        }, {
          value: 10,
          label: '10'
        }, {
          value: 11,
          label: '11'
        }, {
          value: 12,
          label: '12'
        }],
        payInvoiceFlOptions: [{
          value: 1,
          label: '增值'
        }, {
          value: 2,
          label: '普通国税'
        }, {
          value: 3,
          label: '普通地税'
        },{
          value: 4,
          label: '收据'
        }],
        payInvoicePayOptions: [{
          value: 1,
          label: '未付'
        }, {
          value: 2,
          label: '已付'
        }],
        payInvoicePayPlanOptions: [{
          value: 1,
          label: '未建'
        }, {
          value: 2,
          label: '已建'
        }, {
          value: 3,
          label: '已付款无须计划'
        }],
      }
    },
    methods: {
      // 查询当前员工
      loginEmp(){
        this.$axios.get('http://localhost:8088/emp')
          .then(v => {
            this.emp = v.data
          })
          .catch(function (v) {})
      },
      // 查询当前采购
      initData () {
        let purId = this.$route.query.purId
        this.$axios.get('http://localhost:8088/pur-id', {
          params: {
            purId : purId
          }
        })
          .then(v => {
            this.purchase = v.data
            if(this.purchase.customerByConCustomerId === null){
              this.purchase.customerByConCustomerId = ''
            }else {
              this.findContractList(this.purchase.customerByConCustomerId.customerId)
            }
            if(this.purchase.purchaseAppStatus === 0){
              this.active = 0
            }else if (this.purchase.purchaseAppStatus === 1){
              this.active = 1
            }else if (this.purchase.purchaseAppStatus === 2){
              this.active = 2
            }else if (this.purchase.purchaseAppStatus === 3){
              this.active = 2
            }
            this.choiceContact()
          })
          .catch(function (v) {})
      },
      // 选择联系人
      choiceContact(){
        this.$axios.get('http://localhost:8088/contact-list', {
          params: {
            customerId : this.purchase.customerByCustomerId.customerId
          }
        })
          .then(v => {
            this.contactList = v.data
          })
          .catch(function (v) {})
      },
      // 查询所有仓库
      findWarehouse() {
        this.$axios.get('http://localhost:8088/war-list')
          .then(v => {
            this.warehouseList = v.data
          })
          .catch(function (v) {
          })
      },
      //查询合同订单
      findContractList (cusId) {
        this.$axios.get('http://localhost:8088/cus-contract-list-all', {
          params: {
            cusId: cusId
          }
        })
          .then(v => {
            this.contractList = v.data
          })
          .catch(function (v) {})
      },
      // 查询所有产品
      findProduct(){
        this.$axios.get('http://localhost:8088/pro-classify-list')
          .then(v => {
            this.proList = v.data
          })
          .catch(function (v) {})
      },
      // 查询所有详单
      findDetail(){
        let purId = this.$route.query.purId
        this.$axios.get('http://localhost:8088/pur-detail-list', {
          params:{
            purId : purId
          }
        })
          .then(v => {
            this.detailList = v.data
          })
          .catch(function (v) {})
      },
      // 查询采购单待审批表
      findApproval(){
        let purId = this.$route.query.purId
        this.$axios.get('http://localhost:8088/app-pur', {
          params:{
            purId : purId
          }
        })
          .then(v => {
            if (v.data.length !== 0 ){
              this.approval = v.data
            }
          })
          .catch(function (v) {})
      },
      // 查询采购处于待审批状态的审批记录
      findAppRecordBy(){
        let purId = this.$route.query.purId
        this.$axios.get('http://localhost:8088/app-record-pur-app', {
          params:{
            purId : purId
          }
        })
          .then(v => {
            if (v.data.length !== 0 ){
              this.approvalRecord = v.data
            }
          })
          .catch(function (v) {})
      },
      // 查询采购单审批记录表
      findAppRecord(){
        let purId = this.$route.query.purId
        this.$axios.get('http://localhost:8088/app-record-pur-list', {
          params:{
            purId : purId
          }
        })
          .then(v => {
            this.approvalRecordList = v.data
          })
          .catch(function (v) {})
      },
      // 查询入库单
      findStorage(){
        let purId = this.$route.query.purId
        this.$axios.get('http://localhost:8088/sto-pur-list', {
          params:{
            purId : purId
          }
        })
          .then(v => {
            this.storageList = v.data
          })
          .catch(function (v) {})
      },
      // 查询所有boss
      findAllEmp(currPage,pageSize){
        this.innerDialog = true
        this.$axios.get('http://localhost:8088/emp-boss-list',{params: {
            page: currPage,
            size: pageSize,
          }
        })
          .then(v => {
            this.empList = v.data.rows
            this.totalSize = v.data.total
          })
          .catch(function (v) {})
      },
      //boss分页
      changePage (val) {
        // val就是当前页码
        this.findAllEmp(val, this.pageSize)
      },
      // 打开内层dialog
      innerVisible(cusCurrPage, cusPageSize) {
        this.$axios.get('http://localhost:8088/emp-customer-list', {
          params: {
            page: cusCurrPage,
            size: cusPageSize,
          }
        })
          .then(v => {
            this.customerList = v.data.rows
            this.cusTotalSize = v.data.total
          })
          .catch(function (v) {
          })
        this.innerDialogCus = true
      },
      // 查询客户分页
      cusChangePage(val) {
        // val就是当前页码
        this.innerVisible(val, this.cusPageSize)
      },
      // 选择客户
      choiceCustomer(val) {
        this.purchase.customerByConCustomerId = val
        this.purchase.contractByContractId = ''
        this.findContractList(val.customerId)
        this.innerDialogCus = false;
      },
      // 模糊查询客户
      findCustomer() {
        if (this.customerValue != '') {
          this.visible = true
          this.$axios.get('http://localhost:8088/emp-fuzzy-customer-list', {
            params: {
              customerName: this.customerValue
            }
          })
            .then(v => {
              this.customerList2 = v.data
            })
            .catch(function (v) {
            })
        } else {
          this.visible = false
        }
      },
      // 模糊选择客户
      choiceCustomer2(val) {
        this.purchase.customerByConCustomerId = val
        this.purchase.contractByContractId = ''
        this.findContractList(val.customerId)
        this.visible = false
      },
      // 失去焦点关闭模糊搜索框
      closeEmp() {
        this.visible = false
        this.customerValue = ''
      },
      //打开选择产品抽屉
      openPro(){
        if (this.purchase.purchaseAppStatus === 2){
          this.$message({
            message: '该采购单审核通过，不可编辑明细',
            type: 'info'
          });
        }else {
          this.drawer = true
          this.findProduct()
          this.editDetailList = this.detailList
        }
      },
      // 点击选择产品
      clickPro(d,v,e){
        if(d.children.length == 0){
          this.$axios.get('http://localhost:8088/pro-id', {
            params: {
              proId : d.productClassifyId
            }
          })
            .then(v => {
              this.pro = v.data
              if (this.editDetailList.length ===0){
                this.addDetailList()
              }else {
                if (this.isDetailList() === true){
                  this.$message('您添加的产品在列表中已经存在了！');
                }else {
                  this.addDetailList()
                }
              }
            })
            .catch(function (v) {})
        }
      },
      // 将选择产品放过编辑明细集合
      addDetailList(){
        this.editDetail.productByProductId = this.pro.productsByProductClassifyId[0]
        this.editDetail.productDetailPrice = this.pro.productsByProductClassifyId[0].productPrice
        this.editDetailList.push(this.editDetail)
        this.editDetail = {
          productByProductId:'',
          quotationByQuotationId:{},
          productDetailCount: 1,
          productDetailOutNum:0,
          productDetailIntoNum:0,
          productDetailPrice:0,
          productDetailMoney: 0,
          productDetailRemarks: ''
        }
      },
      // 判断所选商品是否重复
      isDetailList(){
        let num = 0
        this.editDetailList.forEach(v=>{
          if (v.productByProductId.productId === this.pro.productsByProductClassifyId[0].productId){
            console.log("重复")
            num = 1;
          }
        })
        if (num == 1){
          return true
        }else {
          return false
        }
      },
      // 从详单删除商品
      deleteDetail(val){
        let index=0;
        for(let i = 0; i < this.editDetailList.length; i++){
          if(this.editDetailList[i].productByProductId.productId === val.productByProductId.productId){
            index = i;
            break;
          }
        }
        this.editDetailList.splice(index,1)
      },
      //保存明细
      savePurchaseDetail(){
        this.drawer = false
        this.purchase.purchaseAmount = this.purchasePrice
        this.addPurchase()
      },
      //关闭抽屉
      closeDrawer(){
        this.purchase.purchaseAmount = this.purchasePrice
      },
      //查询部门员工
      findDeptList () {
        this.$axios.get('http://localhost:8088/dept-emp-list')
          .then(v => {
            this.deptList = v.data
            for(let i = 1;i <= this.deptList.length;i++){
              this.activeName.push(i)
            }
          })
          .catch(function (v) {})
      },
      //打开员工dialog
      openEmpDialog(){
        this.innerDialogEmp = true
        this.findDeptList()
      },
      // 选择员工
      choiceEmp(val) {
        this.purchase.employeeByEmpId = val
        this.innerDialogEmp = false;
      },
      //关闭员工diglog事件
      closeInnerDialogEmp(){
        this.activeName = []
      },
      // 修改采购
      addPurchase() {
        if(this.purchase.customerByConCustomerId === ''){
          this.purchase.customerByConCustomerId = null
        }
        if(this.purchase.contractByContractId === ''){
          this.purchase.contractByContractId = null
        }
        this.$refs.pur.validate((valid) => {
          if (valid) {
            this.$axios.post('http://localhost:8088/save-purchase',
              {
                purchaseId: this. purchase.purchaseId,
                purchaseTheme: this.purchase.purchaseTheme,
                purchaseNo: this.purchase.purchaseNo,
                purchaseDate: this.purchase.purchaseDate,
                purchasePredictDate: this.purchase.purchasePredictDate,
                purchaseStatus: this.purchase.purchaseStatus,
                purchaseSort: this.purchase.purchaseSort,
                purchaseAmount: this.purchase.purchaseAmount,
                purchaseNote: this. purchase.purchaseNote,
                purchaseContactName: this.purchase.purchaseContactName,
                purchaseBill: this.purchase.purchaseBill,
                purchasePaid: this.purchase.purchasePaid,
                purchaseAppStatus: this.purchase.purchaseAppStatus,
                purchaseReturn: this.purchase.purchaseReturn,
                customerByCustomerId: this.purchase.customerByCustomerId,
                employeeByEmpId: this.purchase.employeeByEmpId,
                customerByConCustomerId: this.purchase.customerByConCustomerId,
                contractByContractId: this.purchase.contractByContractId,
                employeeByAppEmpId: this.purchase.employeeByAppEmpId,
                warehouseByWarehouseId: this.purchase.warehouseByWarehouseId,
                productDetailsByPurchaseId: this.detailList
              })
              .then(v => {
                // 1、刷新数据
                this.initData()
                this.findDetail()
                this.findApproval()
                this.findAppRecord()
                this.findAppRecordBy()
                this.findWarehouse()
                this.findContractList()
                this.findStorage()
                this.$message({
                  message: '已保存',
                  type: 'success'
                });
              })
              .catch(function (v) {
              })
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      //删除提示
      repealPur(){
        this.$confirm('此操作将删除采购, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.deletePurchase()
          this.$message({
            type: 'success',
            message: '删除成功!'
          });
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
      },
      // 删除
      deletePurchase () {
        let purId = this.$route.query.purId
        this.$axios.post('http://localhost:8088/delete-purchase',
          this.qs.stringify({purId: purId}))
          .then(v => {
            this.$router.push('/purchase');
          })
          .catch(function (v) {})
      },
      // 申请审批
      saveApproval(){
        if(this.purchase.customerByConCustomerId === ''){
          this.purchase.customerByConCustomerId = null
        }
        if(this.purchase.contractByContractId === ''){
          this.purchase.contractByContractId = null
        }
        //新增审批记录表
        this.approvalRecord.employeeByApplicantEmpId = this.emp
        this.approvalRecord.approvalRecordDate = this.addDate()
        this.approvalRecord.purchaseByPurchaseId = this.purchase
        this.saveAppRecord()
        //新增审批表 审批状态1 1待审批 2同意 3否决 4撤销
        this.approval.approvalTheme = this.purchase.purchaseTheme
        this.approval.approvalContent = '采购库'
        this.approval.approvalStatus = 1
        this.approval.approvalDate = this.addDate()
        this.approval.approvalClassify = 4
        this.approval.employeeByApplicantEmpId = this.emp
        this.approval.purchaseByPurchaseId = this.purchase
        this.saveApp()
        this.$message({
          message: '申请成功',
          type: 'success'
        })
        //修改采购 审批状态为待审批 0待申请 1待审批 2同意 3否决
        this.purchase.purchaseAppStatus = 1
        this.addPurchase ()
      },
      //撤销审批提示
      repealApp(){
        this.$confirm('此操作将撤销审批, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.updateApproval()
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消撤销'
          })
        })
      },
      //撤销审批
      updateApproval(){
        if(this.purchase.customerByConCustomerId === ''){
          this.purchase.customerByConCustomerId = null
        }
        if(this.purchase.contractByContractId === ''){
          this.purchase.contractByContractId = null
        }
        //修改审批记录表
        this.approvalRecord.approvalRecordTime = '1'
        this.approvalRecord.approvalRecordOper = '撤销'
        this.approvalRecord.employeeByApprovalEmpId = this.emp
        this.saveAppRecord()
        //修改审批表审批状态:撤销 1待审批 2同意 3否决 4撤销 5重审
        this.approval.approvalStatus = 4
        this.saveApp()
        this.$message({
          message: '撤销成功',
          type: 'success'
        })
        //修改采购 审批状态为待申请  0待申请 1待审批 2同意 3否决
        this.purchase.purchaseAppStatus = 0
        this.addPurchase ()
      },
      // 审批axois
      saveApp(){
        this.$axios.post('http://localhost:8088/save-approval',
          {
            approvalId:this.approval.approvalId,
            approvalContent:this.approval.approvalContent,
            approvalTheme:this.approval.approvalTheme,
            approvalStay:this.approval.approvalStay,
            approvalStatus: this.approval.approvalStatus,
            approvalClassify:this.approval.approvalClassify,
            approvalOperation:this.approval.approvalOperation,
            approvalDate:this.approval.approvalDate,
            approvalTime:this.approval.approvalTime,
            employeeByApplicantEmpId:this.approval.employeeByApplicantEmpId,
            employeeByApprovalEmpId:this.approval.employeeByApprovalEmpId,
            purchaseByPurchaseId: this.approval.purchaseByPurchaseId
          })
          .then(v => {
            this.innerDialog = false
            this.approval = {
              approvalId:0,
              approvalTheme:'',
              approvalStay:'',
              approvalStatus: '',
              approvalClassify:'',
              approvalOperation:'',
              approvalContent:'',
              approvalDate:'',
              approvalTime:'',
              purchaseByPurchaseId:'',
              employeeByApplicantEmpId:'',
              employeeByApprovalEmpId:null
            }
          })
          .catch(function (v) {})
      },
      // 审批记录axois
      saveAppRecord(){
        this.$axios.post('http://localhost:8088/save-app-record',
          {
            approvalRecordId:this.approvalRecord.approvalRecordId,
            approvalRecordOper:this.approvalRecord.approvalRecordOper,
            approvalRecordNote:this.approvalRecord.approvalRecordNote,
            employeeByApprovalEmpId:this.approvalRecord.employeeByApprovalEmpId,
            employeeByApplicantEmpId:this.approvalRecord.employeeByApplicantEmpId,
            approvalRecordDate:this.approvalRecord.approvalRecordDate,
            approvalRecordTime:this.approvalRecord.approvalRecordTime,
            purchaseByPurchaseId: this.approvalRecord.purchaseByPurchaseId
          })
          .then(v => {
            this.approvalRecord = {
              approvalRecordId:0,
              approvalRecordTime:'',
              approvalRecordOper:'',
              approvalRecordNote:'',
              approvalRecordDate:'',
              employeeByApplicantEmpId:'',
              employeeByApprovalEmpId:null,
              purchaseByPurchaseId:''
            }
          })
          .catch(function (v) {})
      },
      //生成入库单提示
      repealSto(){
        if (this.purchase.purchaseAppStatus === 2){
          this.$confirm('此操作将生成入库单, 是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            this.setStorage()
            this.$message({
              type: 'success',
              message: '生成入库单成功!'
            });
          }).catch(() => {
            this.$message({
              type: 'info',
              message: '已取消生成'
            })
          })
        }else {
          this.$message({
            type: 'info',
            message: '当前采购未审批通过，不允许转成入库单。'
          })
        }
      },
      // 入库单赋值
      setStorage(){
        this.storage.storageTheme = this.purchase.purchaseTheme
        this.storage.storageDate = this.addDate()
        this.storage.storageStatus = 1
        this.storage.warehouseByWarehouseId = this.purchase.warehouseByWarehouseId
        this.storage.employeeByStoEmployeeId = this.emp
        this.storage.employeeByAffEmployeeId = null
        this.storage.purchaseByPurchaseId = this.purchase
        this.storage.returnByReturnId = null
        this.storage.customerByCustomerId = this.purchase.customerByCustomerId
        this.detailList.forEach( v =>{
          if (v.productDetailOutNum !== 0){
            this.stoDetail.storageDetailNum = v.productDetailOutNum
            this.stoDetail.productByProductId = v.productByProductId
            this.stoDetailList.push(this.stoDetail)
            this.stoDetail = {
              storageDetailId:0,
              storageDetailNum:'',
              storageDetailNote:'',
              storageByStorageId:null,
              productByProductId:''
            }
          }
        })
        if(this.purchase.customerByConCustomerId === ''){
          this.purchase.customerByConCustomerId = null
        }
        if(this.purchase.contractByContractId === ''){
          this.purchase.contractByContractId = null
        }
        //将采购单状态改成生产入库单
        if (this.purchase.purchaseStatus === 1){
          this.purchase.purchaseStatus = 2
          this.addPurchase()
        }
        this.saveStorage()
      },
      // 再次生产入库单提示
      repealStoAga(){
        let is = true
        this.storageList.forEach(v => {
          if (v.storageStatus === 1){
            is = false
            return false
          }
        })
        if (is){
          this.$confirm('此操作将生成入库单, 是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            this.setStorage()
            this.$message({
              type: 'success',
              message: '生成入库单成功!'
            });
          }).catch(() => {
            this.$message({
              type: 'info',
              message: '已取消生成'
            })
          })
        }else {
          this.$message({
            type: 'info',
            message: '该采购单已经生成了入库单,如果需要二次补充入库,请在完成第一次入库之后进行！。'
          })
        }
      },
      // 生成入库单
      saveStorage(){
        this.$axios.post('http://localhost:8088/save-storage',
          {
            storageId: this.storage.storageId,
            storageTheme: this.storage.storageTheme,
            storageDate: this.storage.storageDate,
            storageStatus: this.storage.storageStatus,
            storageNote: this.storage.storageNote,
            storageExecutorDate: this.storage.storageExecutorDate,
            warehouseByWarehouseId: this.storage.warehouseByWarehouseId,
            employeeByStoEmployeeId: this.storage.employeeByStoEmployeeId,
            employeeByAffEmployeeId: this. storage.employeeByAffEmployeeId,
            purchaseByPurchaseId: this.storage.purchaseByPurchaseId,
            returnByReturnId: this.storage.returnByReturnId,
            customerByCustomerId: this.storage.customerByCustomerId,
            storageDetailsByStorageId: this.stoDetailList
          })
          .then(v => {
            // 1、刷新数据
            this.$router.push({path: '/storageview', query: {stoId: v.data}});
            this.$message({
              message: '已生成',
              type: 'success'
            });
          })
          .catch(function (v) {
          })

      },
      // 查询付款计划
      findPaymentPlan(){
        let purId = this.$route.query.purId
        this.$axios.get('http://localhost:8088/pay-plan-pur-list', {
          params:{
            purId : purId
          }
        })
          .then(v => {
            this.paymentPlanList = v.data
            this.judgePayPlanPeriods()
          })
          .catch(function (v) {})
      },
      // 新建付款计划
      newPayPlan(){
        this.dialogPla = true
        this.paymentPlan.customerByCustomerId = this.purchase.customerByCustomerId
        this.paymentPlan.paymentPlanDate = this.addDate()
        this.paymentPlan.purchaseByPurchaseId = this.purchase
        this.paymentPlan.employeeByEmpId = this.emp
        this.paymentPlan.paymentPlanStatus = 1
      },
      // 关闭付款计划dialog事件
      closeDialogPayPlan(){
        this.$refs.payPlan.resetFields()
        this.paymentPlan = {
          paymentPlanId:0,
          paymentPlanAmount:'',
          paymentPlanDate:'',
          paymentPlanPeriods:'',
          paymentPlanStatus:'',
          paymentPlanNote:'',
          paymentPlanAppStatus:0,
          customerByCustomerId:'',
          employeeByEmpId:'',
          purchaseByPurchaseId:'',
          employeeByAppEmpId:null
        }
        this.paymentRecords = {
          paymentRecordsId:0,
          paymentRecordsPeriods:'',
          paymentRecordsDate:'',
          paymentRecordsAmount:'',
          paymentRecordsPayStyle:'',
          paymentRecordsWhetherTicket:'',
          paymentRecordsClassify:'',
          paymentRecordsNote:'',
          employeeByEmpId:'',
          customerByCustomerId:'',
          purchaseByPurchaseId:'',
          paymentPlanByPaymentPlanId:'',
          returnByReturnId:null
        }
      },
      addPayPlanJudge(){
        if (this.paymentPlan.paymentPlanId === 0){
          this.$refs.payPlan.validate((valid) => {
            if (valid) {
              if (this.paymentInvoice.paymentInvoiceId !== 0){
                // 修改采购发票为已建立付款计划
                this.paymentInvoice.paymentInvoiceWhetherPayPlan = 2
                this.$axios.post('http://localhost:8088/save-pay-invoice',this.paymentInvoice)
                  .then(v => {
                    this.findPaymentInvoice()
                  })
                  .catch(function (v) {
                  })
              }
              this.addPayPlan()
            } else {
              console.log('error submit!!');
              return false;
            }
          });
        }else {
          this.$refs.payPlan.validate((valid) => {
            if (valid) {
              this.addPayPlan()
            } else {
              console.log('error submit!!');
              return false;
            }
          });
        }

      },
      // 付款计划axios
      addPayPlan() {
        if(this.purchase.customerByConCustomerId == ''){
          this.purchase.customerByConCustomerId = null
        }
        this.$axios.post('http://localhost:8088/save-pay-plan',this.paymentPlan)
          .then(v => {
            this.findPaymentPlan()
            this.dialogPla = false
            this.$message({
              message: '已保存',
              type: 'success'
            });
          })
          .catch(function (v) {
          })
      },
      // 点击跳转到付款计划视图
      openPayView(payId) {
        this.$router.push({path: '/plannedpaymentview', query: {payId: payId}});
      },
      //点击付款生成付款记录
      clickCreatePayRecords(val){
        if (this.purchase.purchaseAppStatus !== 2){
          this.$message({
            type: 'info',
            message: '请先完成采购审批。'
          })
        }else if (val.paymentPlanAppStatus !== 2){
          this.$message({
            type: 'info',
            message: '请先完成付款计划审批。'
          })
        }else {
          this.dialogPay = true
          this.paymentPlan.paymentPlanId = val.paymentPlanId
          this.paymentPlan.paymentPlanAmount = val.paymentPlanAmount
          this.paymentPlan.paymentPlanDate = val.paymentPlanDate
          this.paymentPlan.paymentPlanPeriods = val.paymentPlanPeriods
          this.paymentPlan.paymentPlanStatus = val.paymentPlanStatus
          this.paymentPlan.paymentPlanNote = val.paymentPlanNote
          this.paymentPlan.paymentPlanAppStatus = val.paymentPlanAppStatus
          this.paymentPlan.customerByCustomerId = val.customerByCustomerId
          this.paymentPlan.employeeByEmpId = val.employeeByEmpId
          this.paymentPlan.purchaseByPurchaseId = val.purchaseByPurchaseId
          this.paymentPlan.employeeByAppEmpId = val.employeeByAppEmpId

          this.paymentRecords.paymentRecordsPeriods = val.paymentPlanPeriods
          this.paymentRecords.paymentRecordsDate = this.addDate()
          this.paymentRecords.paymentRecordsAmount = val.paymentPlanAmount
          this.paymentRecords.purchaseByPurchaseId = val.purchaseByPurchaseId
          this.paymentRecords.employeeByEmpId = this.emp
          this.paymentRecords.customerByCustomerId = this.purchase.customerByCustomerId
          this.paymentRecords.paymentPlanByPaymentPlanId = val
          this.paymentRecords.paymentRecordsWhetherTicket = 1
          this.paymentInvoiceList.forEach(value => {
            if (value.paymentInvoicePeriods === this.paymentPlan.paymentPlanPeriods){
              this.paymentInvoice.paymentInvoiceId = value.paymentInvoiceId
              this.paymentInvoice.paymentInvoiceAbstract = value.paymentInvoiceAbstract
              this.paymentInvoice.paymentInvoicePaperType = value.paymentInvoicePaperType
              this.paymentInvoice.paymentInvoiceTicketDate = value.paymentInvoiceTicketDate
              this.paymentInvoice.paymentInvoiceAmount = value.paymentInvoiceAmount
              this.paymentInvoice.paymentInvoicePeriods = value.paymentInvoicePeriods
              this.paymentInvoice.paymentInvoiceWhetherPay = value.paymentInvoiceWhetherPay
              this.paymentInvoice.paymentInvoiceWhetherPayPlan = value.paymentInvoiceWhetherPayPlan
              this.paymentInvoice.paymentInvoiceNo = value.paymentInvoiceNo
              this.paymentInvoice.paymentInvoiceNote = value.paymentInvoiceNote
              this.paymentInvoice.customerByCustomerId = value.customerByCustomerId
              this.paymentInvoice.employeeByEmpId = value.employeeByEmpId
              this.paymentInvoice.purchaseByPurchaseId = value.purchaseByPurchaseId
              this.paymentRecords.paymentRecordsWhetherTicket = 2
            }
          })
        }
      },
      // 查询付款记录
      findPaymentRecords(){
        let purId = this.$route.query.purId
        this.$axios.get('http://localhost:8088/pay-records-pur-list', {
          params:{
            purId : purId
          }
        })
          .then(v => {
            this.paymentRecordsList = v.data
          })
          .catch(function (v) {})
      },
      // 付款记录数据回显
      openPayRecords(val){
        this.dialogPay = true
        this.paymentRecords.paymentRecordsId = val.paymentRecordsId
        this.paymentRecords.paymentRecordsPeriods = val.paymentRecordsPeriods
        this.paymentRecords.paymentRecordsDate = val.paymentRecordsDate
        this.paymentRecords.paymentRecordsAmount = val.paymentRecordsAmount
        this.paymentRecords.paymentRecordsPayStyle = val.paymentRecordsPayStyle
        this.paymentRecords.paymentRecordsWhetherTicket = val.paymentRecordsWhetherTicket
        this.paymentRecords.paymentRecordsClassify = val.paymentRecordsClassify
        this.paymentRecords.paymentRecordsNote = val.paymentRecordsNote
        this.paymentRecords.customerByCustomerId = val.customerByCustomerId
        this.paymentRecords.employeeByEmpId = val.employeeByEmpId
        this.paymentRecords.purchaseByPurchaseId = val.purchaseByPurchaseId
        this.paymentRecords.paymentPlanByPaymentPlanId = val.paymentPlanByPaymentPlanId
        this.paymentRecords.returnByReturnId = val.returnByReturnId
      },
      // 关闭付款记录dialog事件
      closeDialogPayRecords(){
        this.$refs.payRecords.resetFields()
        this.paymentRecords = {
          paymentRecordsId:0,
          paymentRecordsPeriods:'',
          paymentRecordsDate:'',
          paymentRecordsAmount:'',
          paymentRecordsPayStyle:'',
          paymentRecordsWhetherTicket:'',
          paymentRecordsClassify:'',
          paymentRecordsNote:'',
          employeeByEmpId:'',
          customerByCustomerId:'',
          purchaseByPurchaseId:'',
          paymentPlanByPaymentPlanId:'',
          returnByReturnId:null
        }
        this.paymentPlan = {
          paymentPlanId:0,
          paymentPlanAmount:'',
          paymentPlanDate:'',
          paymentPlanPeriods:'',
          paymentPlanStatus:'',
          paymentPlanNote:'',
          paymentPlanAppStatus:0,
          customerByCustomerId:'',
          employeeByEmpId:'',
          purchaseByPurchaseId:'',
          employeeByAppEmpId:null
        }
        this.paymentInvoice = {
          paymentInvoiceId:0,
          paymentInvoiceAbstract:'',
          paymentInvoicePaperType:'',
          paymentInvoiceTicketDate:'',
          paymentInvoiceAmount:'',
          paymentInvoicePeriods:'',
          paymentInvoiceWhetherPay:'',
          paymentInvoiceWhetherPayPlan:'',
          paymentInvoiceNo:'',
          paymentInvoiceNote:'',
          customerByCustomerId:{},
          purchaseByPurchaseId:'',
          employeeByEmpId:{}
        }
      },
      // 生成/修改付款记录
      addPayRecords() {
        if(this.paymentRecords.paymentRecordsId === 0){
          this.$refs.payRecords.validate((valid) => {
            if (valid) {
              // 修改付款计划状态
              this.paymentPlan.paymentPlanStatus = 2
              this.$axios.post('http://localhost:8088/save-pay-plan',this.paymentPlan)
                .then(v => {
                  this.findPaymentPlan()
                })
                .catch(function (v) {
                })
              //修改采购发票为已付
              if (this.paymentInvoice.paymentInvoiceId !== 0){
                this.paymentInvoice.paymentInvoiceWhetherPay = 2
                this.$axios.post('http://localhost:8088/save-pay-invoice',this.paymentInvoice)
                  .then(v => {
                    this.findPaymentInvoice()
                  })
                  .catch(function (v) {
                  })
              }
              // 修改采购单已付金额
              this.purchase.purchasePaid = this.purchasePaid
              this.addPurchase()
              // 生成付款纪录
              this.$axios.post('http://localhost:8088/save-pay-records',this.paymentRecords)
                .then(v => {
                  this.findPaymentRecords()
                  this.dialogPay = false
                })
                .catch(function (v) {
                })
            } else {
              console.log('error submit!!');
              return false;
            }
          })
        }else {
          this.$refs.payRecords.validate((valid) => {
            if (valid) {
              this.$axios.post('http://localhost:8088/save-pay-records',this.paymentRecords)
                .then(v => {
                  this.findPaymentRecords()
                  this.dialogPay = false
                })
                .catch(function (v) {
                })
            } else {
              console.log('error submit!!');
              return false;
            }
          })
        }
      },
      // 新建付款记录提示
      newPaymentRecords(){
        this.$message('请先建立付款计划，审批后由该计划生成付款记录');
      },
      //点击付款生成票据
      clickCreatePayInvoice(val){
        this.dialogTin = true
        this.paymentInvoice.paymentInvoiceAmount = val.paymentRecordsAmount
        this.paymentInvoice.purchaseByPurchaseId = val.purchaseByPurchaseId
        this.paymentInvoice.customerByCustomerId = val.customerByCustomerId
        this.paymentInvoice.paymentInvoiceWhetherPay = 2
        this.paymentInvoice.paymentInvoiceWhetherPayPlan = 3
        this.paymentInvoice.paymentInvoicePeriods = val.paymentRecordsPeriods
        this.paymentInvoice.paymentInvoiceTicketDate = this.addDate()
        this.paymentInvoice.employeeByEmpId = this.emp

        this.paymentRecords.paymentRecordsId = val.paymentRecordsId
        this.paymentRecords.paymentRecordsPeriods = val.paymentRecordsPeriods
        this.paymentRecords.paymentRecordsDate = val.paymentRecordsDate
        this.paymentRecords.paymentRecordsAmount = val.paymentRecordsAmount
        this.paymentRecords.paymentRecordsPayStyle = val.paymentRecordsPayStyle
        this.paymentRecords.paymentRecordsWhetherTicket = val.paymentRecordsWhetherTicket
        this.paymentRecords.paymentRecordsClassify = val.paymentRecordsClassify
        this.paymentRecords.paymentRecordsNote = val.paymentRecordsNote
        this.paymentRecords.customerByCustomerId = val.customerByCustomerId
        this.paymentRecords.employeeByEmpId = val.employeeByEmpId
        this.paymentRecords.purchaseByPurchaseId = val.purchaseByPurchaseId
        this.paymentRecords.paymentPlanByPaymentPlanId = val.paymentPlanByPaymentPlanId
        this.paymentRecords.returnByReturnId = val.returnByReturnId
      },
      // 查询采购发票
      findPaymentInvoice(){
        let purId = this.$route.query.purId
        this.$axios.get('http://localhost:8088/pay-invoice-pur-list', {
          params:{
            purId : purId
          }
        })
          .then(v => {
            this.paymentInvoiceList = v.data
            this.judgePayInvoicePeriods()
          })
          .catch(function (v) {})
      },
      // 付款采购发票数据回显
      openPayInvoice(val){
        this.dialogTin = true
        this.paymentInvoice.paymentInvoiceId = val.paymentInvoiceId
        this.paymentInvoice.paymentInvoiceAbstract = val.paymentInvoiceAbstract
        this.paymentInvoice.paymentInvoicePaperType = val.paymentInvoicePaperType
        this.paymentInvoice.paymentInvoiceTicketDate = val.paymentInvoiceTicketDate
        this.paymentInvoice.paymentInvoiceAmount = val.paymentInvoiceAmount
        this.paymentInvoice.paymentInvoicePeriods = val.paymentInvoicePeriods
        this.paymentInvoice.paymentInvoiceWhetherPay = val.paymentInvoiceWhetherPay
        this.paymentInvoice.paymentInvoiceWhetherPayPlan = val.paymentInvoiceWhetherPayPlan
        this.paymentInvoice.paymentInvoiceNo = val.paymentInvoiceNo
        this.paymentInvoice.paymentInvoiceNote = val.paymentInvoiceNote
        this.paymentInvoice.customerByCustomerId = val.customerByCustomerId
        this.paymentInvoice.employeeByEmpId = val.employeeByEmpId
        this.paymentInvoice.purchaseByPurchaseId = val.purchaseByPurchaseId
      },
      // 关闭采购发票dialog事件
      closeDialogPayInvoice(){
        this.$refs.payInvoice.resetFields()
        this.paymentRecords = {
          paymentRecordsId:0,
          paymentRecordsPeriods:'',
          paymentRecordsDate:'',
          paymentRecordsAmount:'',
          paymentRecordsPayStyle:'',
          paymentRecordsWhetherTicket:'',
          paymentRecordsClassify:'',
          paymentRecordsNote:'',
          employeeByEmpId:'',
          customerByCustomerId:'',
          purchaseByPurchaseId:'',
          paymentPlanByPaymentPlanId:'',
          returnByReturnId:null
        }
        this.paymentInvoice = {
          paymentInvoiceId:0,
          paymentInvoiceAbstract:'',
          paymentInvoicePaperType:'',
          paymentInvoiceTicketDate:'',
          paymentInvoiceAmount:'',
          paymentInvoicePeriods:'',
          paymentInvoiceWhetherPay:'',
          paymentInvoiceWhetherPayPlan:'',
          paymentInvoiceNo:'',
          paymentInvoiceNote:'',
          customerByCustomerId:{},
          purchaseByPurchaseId:'',
          employeeByEmpId:{}
        }
      },
      // 新增发票判断
      addPayInvoiceJudge(){
        if(this.paymentInvoice.paymentInvoiceId === 0){
          this.$refs.payInvoice.validate((valid) => {
            if (valid) {
              // 修改付款记录状态
              if(this.paymentRecords.paymentRecordsId !== 0){
                this.paymentRecords.paymentRecordsWhetherTicket = 2
                this.$axios.post('http://localhost:8088/save-pay-records',this.paymentRecords)
                  .then(v => {
                    this.findPaymentRecords()
                  })
                  .catch(function (v) {
                  })
              }
              // 修改采购单付款票据
              this.purchase.purchaseBill = this.purchaseBill
              this.addPurchase()
              // 生成采购发票
              this.paymentInvoice.paymentInvoiceNo = this.payNo()
              this.addPayInvoice()
            } else {
              console.log('error submit!!');
              return false;
            }
          })
        }else {
          this.$refs.payInvoice.validate((valid) => {
            if (valid) {
              this.addPayInvoice()
            } else {
              console.log('error submit!!');
              return false;
            }
          })
        }
      },
      // 新增发票axiaos
      addPayInvoice() {
        if(this.purchase.customerByConCustomerId === ''){
          this.purchase.customerByConCustomerId = null
        }
        this.$axios.post('http://localhost:8088/save-pay-invoice',this.paymentInvoice)
          .then(v => {
            this.findPaymentInvoice()
            this.dialogTin = false
            this.$message({
              message: '已保存',
              type: 'success'
            });
          })
          .catch(function (v) {
          })
      },
      // 新建采购发票
      newPaymentInvoice(){
        this.dialogTin = true
        this.paymentInvoice.purchaseByPurchaseId = this.purchase
        this.paymentInvoice.customerByCustomerId = this.purchase.customerByCustomerId
        this.paymentInvoice.employeeByEmpId = this.emp
        this.paymentInvoice.paymentInvoiceWhetherPay = 1
        this.paymentInvoice.paymentInvoiceWhetherPayPlan = 1
        this.paymentInvoice.paymentInvoiceTicketDate = this.addDate()
      },
      // 由采购发票生成付款计划
      clickCreatePayPlan(val){
        this.dialogPla = true
        this.paymentPlan.customerByCustomerId = val.customerByCustomerId
        this.paymentPlan.paymentPlanDate = this.addDate()
        this.paymentPlan.paymentPlanPeriods = val.paymentInvoicePeriods
        this.paymentPlan.paymentPlanAmount = val.paymentInvoiceAmount
        this.paymentPlan.purchaseByPurchaseId = val.purchaseByPurchaseId
        this.paymentPlan.employeeByEmpId = this.emp
        this.paymentPlan.paymentPlanStatus = 1

        this.paymentInvoice.paymentInvoiceId = val.paymentInvoiceId
        this.paymentInvoice.paymentInvoiceAbstract = val.paymentInvoiceAbstract
        this.paymentInvoice.paymentInvoicePaperType = val.paymentInvoicePaperType
        this.paymentInvoice.paymentInvoiceTicketDate = val.paymentInvoiceTicketDate
        this.paymentInvoice.paymentInvoiceAmount = val.paymentInvoiceAmount
        this.paymentInvoice.paymentInvoicePeriods = val.paymentInvoicePeriods
        this.paymentInvoice.paymentInvoiceWhetherPay = val.paymentInvoiceWhetherPay
        this.paymentInvoice.paymentInvoiceWhetherPayPlan = val.paymentInvoiceWhetherPayPlan
        this.paymentInvoice.paymentInvoiceNo = val.paymentInvoiceNo
        this.paymentInvoice.paymentInvoiceNote = val.paymentInvoiceNote
        this.paymentInvoice.customerByCustomerId = val.customerByCustomerId
        this.paymentInvoice.employeeByEmpId = val.employeeByEmpId
        this.paymentInvoice.purchaseByPurchaseId = val.purchaseByPurchaseId
      },
      // 判断计划付款期次
      judgePayPlanPeriods(){
        this.paymentPlanList.forEach(v => {
          if (this.payPlanQcOptions.forEach(value => {
            if (value.value === v.paymentPlanPeriods){
              value.disabled = true
            }
          })
          ){
          }
        })
      },
      // 判断采购发票期次
      judgePayInvoicePeriods(){
        this.paymentInvoiceList.forEach(v => {
          if (this.payInvoiceQcOptions.forEach(value => {
            if (value.value === v.paymentInvoicePeriods){
              value.disabled = true
            }
          })
          ){
          }
        })
      },
      // 获取当前日期
      addDate () {
        var date = new Date();
        var seperator1 = "-";
        var seperator2 = ":";
        var month = date.getMonth() + 1<10? "0"+(date.getMonth() + 1):date.getMonth() + 1;
        var strDate = date.getDate()<10? "0" + date.getDate():date.getDate();
        var currentdate = date.getFullYear() + seperator1  + month  + seperator1  + strDate
        return currentdate
      },
      // 发票单号
      payNo() {
        var payNo = "";
        for (var i = 0; i < 4; i++) //j位随机数，用以加在时间戳后面。
        {
          payNo += Math.floor(Math.random() * 10);
        }
        payNo = 'CGFP' + this.addDateNum() + payNo;
        return payNo;
      },
      // 获取当前日期20200206
      addDateNum () {
        var date = new Date();
        var year = date.getFullYear();
        var month = date.getMonth() + 1;
        var strDate = date.getDate();
        if (month >= 1 && month <= 9) {
          month = "0" + month;
        }
        if (strDate >= 0 && strDate <= 9) {
          strDate = "0" + strDate;
        }
        var currentdate = year  + month  + strDate;
        return currentdate;
      },
      // 导出PDF
      printPdf(val){
        this.$router.push({path: '/printpurchase', query: {purId: val}});
      },
      goContract(val){
        this.$router.push({path: '/contractview', query: {contractId: val}});
      }
    },
    computed:{
      purchasePrice(){
        var total = 0;
        this.editDetailList.forEach(p=>{
          var number = p.productDetailCount===undefined?0:parseFloat(p.productDetailCount);
          total +=  number* parseFloat(p.productDetailPrice);
        });
        return total;
      },
      purchasePaid(){
        var total = 0;
        this.paymentRecordsList.forEach(v=>{
          total += parseFloat(v.paymentRecordsAmount);
        });
        total +=  parseFloat(this.paymentRecords.paymentRecordsAmount)
        return total;
      },
      purchaseBill(){
        var total = 0;
        this.paymentInvoiceList.forEach(v=>{
          total += parseFloat(v.paymentInvoiceAmount);
        });
        total +=  parseFloat(this.paymentInvoice.paymentInvoiceAmount)
        return total;
      }
    },
    created() {
      this.loginEmp()
      this.initData()
      this.findDetail()
      this.findApproval()
      this.findAppRecord()
      this.findAppRecordBy()
      this.findWarehouse()
      this.findContractList()
      this.findStorage()
      this.findPaymentPlan()
      this.findPaymentRecords()
      this.findPaymentInvoice()
    },
    filters: {
      formatDate: function(time) {
        if(time!=null&&time!="")
        {
          var date = new Date(time);
          return formatTimeToStr(date, "yyyy-MM-dd hh:mm");
        }else{
          return "";
        }
      },
      formatDateJudge: function(time) {
        if(time != null && time != "")
        {
          let date = new Date(time);
          let currentDate = new Date()
          let seperator1 = "-";
          let month = currentDate.getMonth() + 1<10? "0"+(currentDate.getMonth() + 1):currentDate.getMonth() + 1;
          let strDate = currentDate.getDate()<10? "0" + currentDate.getDate():currentDate.getDate();
          let today = currentDate.getFullYear() + seperator1  + month  + seperator1  + strDate
          let todayTime = new Date(today)
          let yesterday = todayTime.setDate(todayTime.getDate() - 1)
          let beforeYesterday = todayTime.setDate(todayTime.getDate() - 1)
          let tomorrow = todayTime.setDate(todayTime.getDate() + 3)
          let afterTomorrow = todayTime.setDate(todayTime.getDate() + 1)
          todayTime.setDate(todayTime.getDate() - 2)
          if (date.getTime() === todayTime.getTime()){
            return '今天'
          }else if (date.getTime() ===  yesterday){
            return '昨天'
          }else if (date.getTime() ===  beforeYesterday){
            return '前天'
          }else if (date.getTime() ===  tomorrow){
            return '明天'
          }else if (date.getTime() ===  afterTomorrow){
            return '后天'
          }else {
            return time
          }
        }else{
          return "";
        }
      }
    }
  }
</script>

<style scoped>
</style>
